﻿import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import Qt.labs.platform 1.1

Window {
    id: window
    // width: 1280
    // height: 640
    width: 1088
    height: 544
    minimumWidth: 1088
    minimumHeight: 544
    visible: true
    title: qsTr("Uart2Relay v0.2 (Power by TimeChicken)")
    // flags: Qt.FramelessWindowHint

    MainPage { }
    // MainPageTest { }

    SystemTrayIcon {
        id: systemTrayIcon
        property bool quiting: false
        visible: true
        icon.source: "qrc:/images/favicon.ico"
        tooltip: "Uart2Relay"
        menu: Menu {
            MenuItem {
                text: qsTr("Quit")
                onTriggered:  {
                    systemTrayIcon.quiting = true
                    Qt.quit()
                }
            }
        }

        onActivated: (reason) => {
            window.show()
            window.raise()
            window.requestActivate()
        }

        onMessageClicked: {
            console.log("Message clicked")
        }

        Component.onCompleted: {
            showMessage("Uart2Relay", "The program has started.")
        }
    }

    onClosing: (close) => {
        if (!systemTrayIcon.quiting) {
            close.accepted = false
            window.hide()
            systemTrayIcon.showMessage("Uart2Relay", "The program has been minimized, "
                                       + "click the system tray icon to restore the interface again.")
        }
    }

}
